<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
		<script>
			const obj = new Proxy([], {
				// target目标对象 , propKey键名 receiver是proxy代理的目标对象
				get: function (target, propKey, receiver) {
					console.log(`getting ${propKey}!`)
					console.dir(Reflect.get(target, propKey, receiver))
					return Reflect.get(target, propKey, receiver)
				},
				defineProperty(target, prop, receiver) {
					return Reflect.defineProperty(target, prop, receiver)
				},
				set: function (target, propKey, value, receiver) {
					console.log(target)
					console.log(`setting ${propKey}!`)
					console.log(value)
					return Reflect.set(target, propKey, value, receiver)
				},
			})
			// obj.push(123)
		</script>
		<script>
			const handler = {
				get: function (target, name) {
					if (name === 'prototype') {
						return Object.prototype
					}
					return 'Hello, ' + name
				},

				apply: function (target, thisBinding, args) {
					console.log(args)
					return args[0]
				},

				construct: function (target, args) {
					return fn
				},
			}
			const fn = function (x, y) {
				return x + y
			}
			const fproxy = new Proxy(fn, handler)
			fproxy.prototype.add = 123
			// console.dir(fn.prototype.__proto__ === Object.prototype) 
			console.log(fproxy.prototype === fn.prototype.__proto__)
			console.log(Object.prototype)
			// fproxy(1, 2) // 1
			// new fproxy(1, 2) // {value: 2}
			// fproxy.prototype === Object.prototype // true
			// fproxy.foo === "Hello, foo" // true
		</script>
	</head>

	<body></body>
</html>
